﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;
using Entities;

namespace ShoppingCartWEB
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        private CategoryManager pm = new CategoryManager();
        private SupplierManager sm = new SupplierManager();
        public ShoppingCard card;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                foreach (Category c in pm.AllCategory())
                {
                        listCategory.Items.Add(c.CategoryName.ToString());
                }

                rptSupplier.DataSource = sm.AllSupplier();
                rptSupplier.DataBind();

                rptCategory.DataSource = pm.AllCategory();
                rptCategory.DataBind();            
            }
            card = new ShoppingCard();
            card.Cards = GetCart();
        }

       private Dictionary<Product, int> GetCart()
        {
            if (Session["Cart"] == null)
                Session.Add("Cart", new Dictionary<Product, int>());
            return (Dictionary<Product, int>)Session["Cart"];
        }

       protected void btnAdvSearch_Click(object sender, EventArgs e)
       {
           Response.Redirect("Products.aspx?pr=" + ddlSearchByPrice.SelectedItem.Value);
       }

       protected void btnQuickSearch_Click(object sender, EventArgs e)
       {         
                       Response.Redirect("Products.aspx?txt=" + txtQuickSearch.Text + "&caid=" + listCategory.Text);               
       }       
    }
}
